package com.zhc.dejingapi.controller;


import com.bstek.ureport.export.ExportManager;
import com.zhc.dejingapi.utils.ExportUtils;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class urePortController {
    @Autowired
    private ExportManager exportManager;


    //https://blog.csdn.net/lige12/article/details/131829472
    // 重启项目，浏览器输入 http://localhost:8090/user/generatePDF
    @SneakyThrows
    @RequestMapping("/generatePDF")
    public Map<String, Object> generatePDF(){
        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("userName","张三");
        dataMap.put("age","20");
        dataMap.put("sex","男");
        dataMap.put("grade","大三");
        dataMap.put("birthDate","2003-01-01");
        dataMap.put("address","广州市天河区");
        dataMap.put("school","广东工业大学");
        String filePath="D:/userInfo.pdf";
        ExportUtils.exportPdf(exportManager,"file:userInfo.ureport.xml",filePath,dataMap);
        //返回页面信息
        Map<String,Object> result = new HashMap<>();
        result.put("result","Success");
        result.put("data",dataMap);
        return result;
    }
    @SneakyThrows
    @RequestMapping("/generateExcel")
    public Map<String, Object> generateExcel(){
        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("userName","张三");
        dataMap.put("age","20");
        dataMap.put("sex","男");
        dataMap.put("grade","大三");
        dataMap.put("birthDate","2003-01-01");
        dataMap.put("address","广州市天河区");
        dataMap.put("school","广东工业大学");
        String filePath="D:/userInfo.xls";
        ExportUtils.exportExcel(exportManager,"file:userInfo.ureport.xml",filePath,dataMap);
        //返回页面信息
        Map<String,Object> result = new HashMap<>();
        result.put("result","Success");
        result.put("data",dataMap);
        return result;
    }

}